package com.cxrj.zhsq.leaseManage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cxrj.zhsq.leaseManage.entity.PropertyGoods;
import com.cxrj.zhsq.leaseManage.entity.PropertyGoodsType;
import com.cxrj.zhsq.leaseManage.service.GoodsService;

@RestController
public class GoodsController {

	@Resource
	private GoodsService goodsService;

	/**
	 * 分页查询租借类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyGoodsTypes", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> selectPropertyGoodsTypes(HttpServletRequest request, HttpServletResponse response) {
		return goodsService.seleteGoodsTypePage(request, response);
	}

	/**
	 * 分页查询租借信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyGoodss", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> selectPropertyGoodss(HttpServletRequest request, HttpServletResponse response) {
		return goodsService.seleteGoodsPage(request, response);
	}

	/**
	 * 添加租借类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertPropertyGoodsType", method = RequestMethod.POST)
	public Map<String, Object> insertPropertyGoodsType(PropertyGoodsType propertyGoodsType, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			propertyGoodsType.setCommunityId(request.getSession().getAttribute("communityId").toString());
			resultMap = goodsService.insertGoodsType(propertyGoodsType);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 添加租借信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertPropertyGoods", method = RequestMethod.POST)
	public Map<String, Object> insertPropertyGoods(PropertyGoods propertyGoods, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			propertyGoods.setCommunityId(request.getSession().getAttribute("communityId").toString());
			resultMap = goodsService.insertGoods(propertyGoods);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 修改租借类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "updatePropertyGoodsType", method = RequestMethod.POST)
	public Map<String, Object> updatePropertyGoodsType(PropertyGoodsType propertyGoodsType, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = goodsService.updateGoodsType(propertyGoodsType);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 修改租借信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "updatePropertyGoods", method = RequestMethod.POST)
	public Map<String, Object> updatePropertyGoods(PropertyGoods propertyGoods, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = goodsService.updateGoods(propertyGoods);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 根据id查询租借类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyGoodsTypeById", method = RequestMethod.POST)
	public Map<String, Object> selectPropertyGoodsTypeById(String id, HttpServletRequest request) {
		return goodsService.seleteGoodsTypeById(id);
	}

	/**
	 * 根据id查询租借信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyGoodsById", method = RequestMethod.POST)
	public Map<String, Object> selectPropertyGoodsById(String id, HttpServletRequest request) {
		return goodsService.seleteGoodsById(id);
	}

	/**
	 * 查询使用租借类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyGoodsTypeByAll", method = RequestMethod.POST)
	public Map<String, Object> selectPropertyGoodsTypeByAll(HttpServletRequest request) {
		return goodsService.selectGoodsTypeByAll(request);
	}
}
